//
//  UIBarButtonItem+HMBarButtonItem.m
//  swift-新浪微博OC版-8-29
//
//  Created by 赵玉忠 on 16/8/29.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "UIBarButtonItem+HMBarButtonItem.h"

@implementation UIBarButtonItem (HMBarButtonItem)
+(instancetype)HMBarButtonItem:(NSString *)imgName andWithTitle:(NSString *)title andWithTarget:(id)target andWithAction:(SEL)action{
    UIBarButtonItem *item = [UIBarButtonItem new];
    UIButton *btn = [[UIButton alloc]init];
    if (action != nil) {
        [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
    if (imgName != nil) {
        [btn setImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
        NSString *str = [NSString stringWithFormat:@"%@_highlighted",imgName];
        [btn setImage:[UIImage imageNamed:str] forState:UIControlStateHighlighted];
    }
    if (title != nil) {
        [btn setTitle:title forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
    }
    [btn sizeToFit];
    item.customView = btn;
    return item;
}
@end
